function addEntity(entityName, entityUri){
	$("#entity_list")
	.append(
			'<div><code>'
			+ entityName
			+'</code><input type="hidden" name="entityUri" value="'
			+ entityUri
			+ '"/>' 
			+'<button style="margin-left:50px;margin-bottom:2px" type="button" class="btn btn-warning" onclick="deleteEntity(this)">删除</button></div>');
}

function deleteEntity(delbtn) {
	$(delbtn).parent().remove();
}

function saveEntityZone(){
	$("#entity_zone_panel").modal('hide');
	$("#entity_zone_panel input[type='checkbox']").each(function(){
		if ($(this).prop("checked")){
			alert($(this).val());
			addEntity( $(this).parent().text(),$(this).val());
			$(this).removeAttr("checked");
		}
	});
	
};

function deleteEntityZone(entityZoneId, deleteBtn) {
	//var uri = $(deleteBtn).siblings('input').val();
	var projectId = $("input[name='projectId']").val();
	$.ajax({
		url : '/ManEnv/entityZone/' + projectId + "/" + entityZoneId,
		type : 'DELETE',
		success : function(data) {
			if(data.result == "true"){
				alert("删除成功!");	
				$(deleteBtn).parents("tr").remove(); // 删除第一个tr元素
			}else{
				alert("删除失败!");
			}
		}
	});
};

function deleteEntityZoneCategory(entityZoneId, deleteBtn) {
	var projectId = $("input[name='projectId']").val();
	$.ajax({
		url : '/ManEnv/entityZoneCategory/' + projectId + "/" + entityZoneId,
		type : 'DELETE',
		success : function(data) {
			if(data.result == "true"){
				alert("删除成功!");	
				$(deleteBtn).parents("tr").remove(); // 删除第一个tr元素
			}else{
				alert("删除失败!");
			}
		}
	});
};


function showDeletePanel(entityZoneId, deleteBtn){
    $("#delete-entity-zone-panel").modal({
        "show" : true,
        "backdrop" : false
    });
    $("#delete-entity-zone-btn").unbind("click");
    $("#delete-entity-zone-btn").click(function(){
    	deleteEntityZone(entityZoneId, deleteBtn);
    });
}

function showEntityZoneCategoryDeletePanel(entityZoneId, deleteBtn){
    $("#delete-entity-zone-category-panel").modal({
        "show" : true,
        "backdrop" : false
    });
    $("#delete-entity-zone-category-btn").unbind("click");
    $("#delete-entity-zone-category-btn").click(function(){
    	deleteEntityZoneCategory(entityZoneId, deleteBtn);
    });
}

